                                                                                                                                                                                                                                                                package com.binhai.springboot.menu.controller;

import com.binhai.springboot.menu.bean.MenuBean;
import com.binhai.springboot.menu.service.MenuService;
import com.binhai.springboot.org.bean.OrgBean;
import com.binhai.springboot.org.service.OrgService;
import com.binhai.springboot.user.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.awt.*;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/menu")
public class MenuController {

    @Autowired
    private MenuService service;

    @Autowired
    private HttpSession session;

    @RequestMapping("/toMain.do")
    public String toMain(){

        return "menu/main";
    }

    @RequestMapping("/getAllData.do")
    @ResponseBody
    public List getAllData(){

        return service.getAllData();
    }

    @RequestMapping("/getAllTreeData.do")
    @ResponseBody
    public List getAllTreeData(){

        return service.getAllTreeData();
    }
    @RequestMapping("/selectData.do")
    @ResponseBody
    public List selectData(@RequestBody MenuBean bean){

        return service.selectData(bean.getName());
    }

    @RequestMapping("/saveData.do")
    @ResponseBody
    public Map saveData(@RequestBody MenuBean bean){

        return service.saveData(bean);
    }
    @RequestMapping("/updateData.do")
    @ResponseBody
    public Map updateData(@RequestBody MenuBean bean){

        return service.updateData(bean);
    }
    @RequestMapping("/deleteData.do")
    @ResponseBody
    public Map deleteData(@RequestBody MenuBean bean){

        return service.deleteData(bean);
    }
    @RequestMapping("/getAllMenu.do")
    @ResponseBody
    public MenuBean getAllMenu(){

        return service.getAllMenu();
    }

    /**
     * 查询当前用户的所有的菜单
     * @param
     * @return
     */
    @RequestMapping("/getCurrentUserAllMenu.do")
    @ResponseBody
    public MenuBean getCurrentUserAllMenu(){
        //获取当前用户
        UserBean user = (UserBean) session.getAttribute("user");
        return service.getCurrentUserAllMenu(user);

    }
}
